package com.skillworld.webapp.model.lesson;

import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@org.hibernate.annotations.BatchSize(size=10)
@Table(name="Exam")
public class Exam
{
    private Long examId;
    private Lesson lesson;
    private String examFile;
    private Calendar creationDate;
    private boolean enabled;
    
    
    protected Exam()
    {

    }
    
    public Exam(Lesson lesson, String examFile)
    {
        this.lesson = lesson;
        this.examFile = examFile;
        this.creationDate = Calendar.getInstance();
        this.enabled = true;
    }
    
    
    @SequenceGenerator(name="ExamIdGenerator",sequenceName="ExamSeq")
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO,generator="ExamIdGenerator")
    @Column(name="idExam")
    public Long getExamId()
    {
        return examId;
    }
    
    protected void setExamId(Long examId)
    {
        this.examId = examId;
    }
    
    @ManyToOne(optional=false,fetch=FetchType.LAZY)
    @JoinColumn(name="idLesson")
    public Lesson getLesson()
    {
        return lesson;
    }
    
    public void setLesson(Lesson lesson)
    {
        this.lesson = lesson;
    }
    
    @Column(name="examFile")
    public String getExamFile() 
    {
        return examFile;
    }
    
    protected void setExamFile(String examFile)
    {
        this.examFile = examFile;
    }
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="creationDate")
    public Calendar getCreationDate() 
    {
        return creationDate;
    }

    protected void setCreationDate(Calendar creationDate)
    {
        this.creationDate = creationDate;
    }

    @Column(name="enabled")
    public boolean isEnabled()
    {
        return enabled;
    }
    
    public void setEnabled(boolean enabled)
    {
        this.enabled = enabled;
    }

    public void disable()
    {
        setEnabled(false);
    }
}
